#include "SharedVariables.fxh"

float4x4 World;

float3 lightColor;
float lightRadius;
float lightIntensity = 1.0f;
float3 lightPosition;

float3 cameraPosition;
float4x4 InverseViewProj;

sampler depthSampler = sampler_state
{
	Texture=(DepthRT);
	MAGFILTER = POINT;
	MINFILTER = POINT;
	MIPFILTER = POINT;
	AddressU = Clamp;
	AddressV = Clamp;
};

sampler diffuseSampler = sampler_state
{
	Texture=(DiffuseRT);
	MAGFILTER = POINT;
	MINFILTER = POINT;
	MIPFILTER = POINT;
	AddressU = Clamp;
	AddressV = Clamp;
};

sampler normalSampler = sampler_state
{
	Texture=(NormalRT);
	MAGFILTER = POINT;
	MINFILTER = POINT;
	MIPFILTER = POINT;
	AddressU = Clamp;
	AddressV = Clamp;
};

struct PointVSInput
{
    float3 Position : POSITION0;
};

struct PointVSOutput
{
    float4 Position : POSITION0;
    float4 ScreenPosition : TEXCOORD0;
};

PointVSOutput PointVS(PointVSInput input)
{
    PointVSOutput output;

    float4 worldPosition = mul(float4(input.Position, 1), World);
    output.Position = mul(worldPosition, ViewProj);
    output.ScreenPosition = output.Position;

    return output;
}

float4 PointPS(PointVSOutput input) : COLOR0
{
	float4 position;
	float3 normal;
	float specularPower, specularIntensity;
	
	FillVariables(input.ScreenPosition, normalSampler, diffuseSampler, depthSampler, InverseViewProj, normal, specularPower, specularIntensity, position);
	
	return LightEquation(lightPosition, position, lightRadius, normal, lightColor, cameraPosition, specularIntensity, specularPower, 1);
}

technique PointLight
{
	pass Pass0
	{
		VertexShader = compile vs_2_0 PointVS();
		PixelShader = compile ps_2_0 PointPS();
	}
}